home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / lds / key.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  232 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "x.h"
  19. #include "defines.h"
  20. #include "externals.h"
  21. #include "xexterns.h"
  22.  
  23. /* external routines called in this file */
  24. extern void save_to_file(), redraw(), init_gen(), FlushBuffer(), Clear();
  25. extern void init_color(), zerospa(), zerohist(), FlushHisbuf(), draw_spa();
  26. extern void Spin(), FlushPixmap();
  27.  
  28. void
  29. Getkey(event)
  30. XKeyEvent *event;
  31. {
  32.     unsigned char key;
  33.     static int i, spinning=0, spindir=0;
  34.     extern void Cleanup(), write_cmap();
  35.  
  36.     if (XLookupString(event, (char *)&key, sizeof(key), (KeySym *)0,
  37.             (XComposeStatus *) 0) > 0)
  38.                 switch (key) {
  39.     case '\015': /* write out current colormap to $HOME/.<prog>map */
  40.             write_cmap(dpy,cmap,Colors,numcolors,"lds","Lds");
  41.             break;
  42.     case '1':                    
  43.     case '2':                    
  44.     case '3':                    
  45.     case '4':                    
  46.     case '5':                    
  47.     case '6':                    
  48.     case '7':                    
  49.     case '8':                    
  50.     case '9':                    /* set frequency of display */
  51.             freq = atoi(&key);
  52.             break;
  53.     case '<':
  54.             freq /= 2;
  55.             if (freq < 1)
  56.                 freq = 1;
  57.             break;
  58.     case '>':
  59.             freq *= 2;
  60.             break;
  61.     case '-':
  62.             freq--;
  63.             if (freq < 1)
  64.                 freq = 1;
  65.             break;
  66.     case '+':
  67.             freq++;
  68.             break;
  69.     case 'a':
  70.     case 'A': save_to_file(spamap); break;
  71.     case 'B':                    /* begin again */
  72.             Clear(canvas);
  73.             if (sflag) {
  74.                 Clear(spahis);
  75.                 zerospa();
  76.             }
  77.             if (hflag) {
  78.                 Clear(hiswin);
  79.                 zerohist();
  80.             }
  81.             Cflag=0;
  82.             xpoint = ypoint = 0;
  83.             init_gen();
  84.             break;
  85.     case 'c':                    /* toggle curve/cell display */
  86.             cflag = (!cflag);
  87.             Cflag=0;
  88.             Clear(canvas);
  89.             break;
  90.     case 'd':                    /* don't erase */
  91.             eflag=0;
  92.             break;
  93.     case 'D': 
  94.             if (cflag)
  95.               FlushBuffer(dpy,canvas,pixmap,Data_GC,&Points,mincolor,numcolors);
  96.             else {
  97.               FlushPixmap(dpy,pixmap,Data_GC,&Points,mincolor,numcolors);
  98.               XCopyArea(dpy,pixmap,canvas,Data_GC[0],0,0,width,height,0,0);
  99.             }
  100.             if (sflag)
  101.                 FlushHisbuf();
  102.             break;
  103.     case 'e':                /* recalculate and display spatial histogram */
  104.             if (sflag)
  105.                 draw_spa();
  106.             break;
  107.     case 'E':                /* clear screen and show one gen at a time */
  108.             Clear(canvas);
  109.             eflag=1;
  110.             break;
  111.     case 'f':
  112.     case 'F': save_to_file(pixmap); break;
  113.     case 'h':                    /* toggle spatial histogram tracking */
  114.             sflag = (!sflag);
  115.             zerospa();
  116.             if (sflag) {
  117.                 XMapRaised(dpy, spahis);
  118.                 init_color(dpy,spahis,spcmap,Colors,mincolor,mincolor,numcolors,
  119.                         numwheels, "lds", "Lds", 0);
  120.                 Clear(spahis);
  121.             }
  122.             else
  123.                 XUnmapWindow(dpy, spahis);
  124.             break;
  125.     case 'H':                    /* toggle site histogram tracking */
  126.             hflag = (!hflag);
  127.             if (hflag) {
  128.                 XMapRaised(dpy, hiswin);
  129.                 init_color(dpy,hiswin,hicmap,Colors,mincolor,mincolor,numcolors,
  130.                         numwheels, "lds", "Lds", 0);
  131.             }
  132.             else {
  133.                 XUnmapWindow(dpy, hiswin);
  134.                 zerohist();
  135.             }
  136.             break;
  137.     case 'i': if (stripe_interval > 0) {
  138.                 stripe_interval--;
  139.                   if (displayplanes > 1) {
  140.                   if (event->window == canvas)
  141.                     init_color(dpy,canvas,cmap,Colors,mincolor,mincolor,
  142.                                 numcolors, numwheels, "lds", "Lds", 0);
  143.                   else if (event->window == spahis)
  144.                     init_color(dpy,spahis,spcmap,Colors,mincolor,mincolor,
  145.                                 numcolors, numwheels, "lds", "Lds", 0);
  146.                   if (event->window == hiswin)
  147.                     init_color(dpy,hiswin,hicmap,Colors,mincolor,mincolor,
  148.                                 numcolors, numwheels, "lds", "Lds", 0);
  149.                 }
  150.               }
  151.               break;
  152.     case 'I': stripe_interval++;
  153.                 if (displayplanes > 1) {
  154.                   if (event->window == canvas)
  155.                     init_color(dpy,canvas,cmap,Colors,mincolor,mincolor,
  156.                                 numcolors, numwheels, "lds", "Lds", 0);
  157.                   else if (event->window == spahis)
  158.                     init_color(dpy,spahis,spcmap,Colors,mincolor,mincolor,
  159.                                 numcolors, numwheels, "lds", "Lds", 0);
  160.                   if (event->window == hiswin)
  161.                     init_color(dpy,hiswin,hicmap,Colors,mincolor,mincolor,
  162.                                 numcolors, numwheels, "lds", "Lds", 0);
  163.               }
  164.           break;
  165.     case 'p':                    /* toggle display phase differences */
  166.             pflag=(!pflag);
  167.             break;
  168.     case 'P':                    /* draw points */
  169.             if (!Pflag)
  170.                 Clear(canvas);
  171.             Pflag=1;
  172.             break;
  173.     case 'L':                    /* draw lines, not points */
  174.             if (Pflag)
  175.                 Clear(canvas);
  176.             Pflag=0;
  177.             break;
  178.     case 'm':                    /* don't single step */
  179.             sflag=0;
  180.             break;
  181.     case 'R':
  182.             spinning = 0; break;
  183.     case 'S': spinning=1; spindir=(!spindir);
  184.            Spin(dpy, cmap, Colors, mincolor, numcolors, 0, spindir); 
  185.            break;
  186.     case 's':                    /* single step */
  187.             sflag=1;
  188.             break;
  189.     case 'W': if (numwheels < MAXWHEELS)
  190.             numwheels++;
  191.            else
  192.             numwheels = 0;
  193.            if (displayplanes > 1) {
  194.                 if (event->window == canvas)
  195.                     init_color(dpy,canvas,cmap,Colors,mincolor,mincolor,
  196.                                 numcolors, numwheels, "lds", "Lds", 0);
  197.                 else if (event->window == spahis)
  198.                     init_color(dpy,spahis,spcmap,Colors,mincolor,mincolor,
  199.                                 numcolors, numwheels, "lds", "Lds", 0);
  200.                 if (event->window == hiswin)
  201.                     init_color(dpy,hiswin,hicmap,Colors,mincolor,mincolor,
  202.                                 numcolors, numwheels, "lds", "Lds", 0);
  203.            }
  204.            break;
  205.     case 'w': if (numwheels > 0)
  206.             numwheels--;
  207.            else
  208.             numwheels = MAXWHEELS;
  209.            if (displayplanes > 1) {
  210.                 if (event->window == canvas)
  211.                     init_color(dpy,canvas,cmap,Colors,mincolor,mincolor,
  212.                                 numcolors, numwheels, "lds", "Lds", 0);
  213.                 else if (event->window == spahis)
  214.                     init_color(dpy,spahis,spcmap,Colors,mincolor,mincolor,
  215.                                 numcolors, numwheels, "lds", "Lds", 0);
  216.                 if (event->window == hiswin)
  217.                     init_color(dpy,hiswin,hicmap,Colors,mincolor,mincolor,
  218.                                 numcolors, numwheels, "lds", "Lds", 0);
  219.            }
  220.            break;
  221.     case 'x': Clear(event->window); break;
  222.     case 'X':                    /* toggle complex dynamical systems mode */
  223.             xflag=(!xflag);
  224.             break;
  225.     case 'q':
  226.     case 'Q': Cleanup(); exit(0); break;
  227.     default:  break;
  228.     }
  229.     if (spinning)
  230.         Spin(dpy, cmap, Colors, mincolor, numcolors, 0, spindir); 
  231. }
  232.